<template>
  <div
    id="chart"
    style="
      width: 350px;
      height: 220px;
      background-color: rgb(228, 249, 250);
      margin: 15px 0;
    "
    ref="chart"
  ></div>
</template>
<script>
//import * as Echarts from 'echarts';
export default {
  name: "echarts01",
  data() {
    return {
      chart: null,
    };
  }, //图表实例
  mounted() {
    this.init();
  },
  methods: {
    init() {
      //2.初始化
      this.chart = this.$Echarts.init(this.$refs.chart);
      //3.配置数据
      let option = {
        tooltip: {
          trigger: "axis",
          axisPointer: {
            // 坐标轴指示器，坐标轴触发有效
            type: "shadow", // 默认为直线，可选为：'line' | 'shadow'
          },
        },
        grid: {
          left: "3%",
          right: "4%",
          bottom: "3%",
          containLabel: true,
        },
        xAxis: [
          {
            type: "category",
            data: ["05/15", "05/19", "05/23", "05/27", "05/31"],
            axisTick: {
              alignWithLabel: true,
            },
          },
        ],
        yAxis: {
          data: ["轻度", "中度", "重度"],
        },
        series: [
          {
            name: "直接访问",
            type: "bar",
            barWidth: "60%",
            data: [],
          },
        ],
      };
      // 4.传入数据
      this.chart.setOption(option);
    },
  },
};
</script>
